<!DOCTYPE html>
<html>

<head>
    <% include global/meta.html %>
        <% include global/top-css.html %>
        <title>yuscms</title>
</head>

<body>

                        <main class="main" data-info="<%=admin.permission%>">
                            <div class="ys-admin-pos c-a1a3aa">
                                首页
                                <span class="f-sum">></span>
                                <span class="c-565b6d">站内消息</span>
                                <span class="f-sum">></span>
                                <span class="c-565b6d">更新</span>
                            </div>

                            <div class="ys-admin-tablist">
                                <div class="ys-admin-tab-header row justify-content-b">
                                    <p class="f-14 c-565b6d pl-8 pt-6"></p>
                                </div>

                                <div class="mr-10 ml-10" v-loading="loading">
                                    <form @submit.prevent="checkForm" name="form">
                                        <ul class="overflow-h pb-20">
                                            <li class="row pd-10 f-14">
                                                <div class="col-hd">
                                                    <label class="label">消息标题</label>
                                                </div>
                                                <div class="col-10">
                                                    <input type="text" name="title" class="input" v-model="params.title" />
                                                </div>
                                            </li>

                                            <li class="row pd-10 f-14">
                                                <div class="col-hd">
                                                    <label class="label">消息内容</label>
                                                </div>
                                                <div class="col-10">
                                                    <textarea name="content" class="textarea" cols="30" rows="3" v-model="params.content"></textarea>
                                                </div>
                                            </li>
                                            <li class="pd-10 mt-35">
                                                <div class="col-hd">
                                                    &nbsp;&nbsp;&nbsp;&nbsp;
                                                </div>
                                                <div class="col-bd row ml-35">
                                                    <input name="send" class="btn btn-sure ml-35" type="submit" value="确定发布" />
                                                    <input name="send" class="btn btn-reset ml-35" type="reset" value="重置" />
                                                </div>
                                            </li>

                                        </ul>


                                    </form>
                                </div>


                            </div>
                        </main>
              
    <% include global/all-js.html %>
        <script>
            var vm = new Vue({
                el: '.main',
                data: {
                    loading: true,
                    level: [],
                    params: {
                        title: '',
                        content: '',
                        id: $m.getParams('id')
                    }
                },
                methods: {

                    queryById() {
                        let _this = this;
                        axios.get('/api/admin/msg/queryId', {
                            params: { id: _this.params.id }
                        }).then((data) => {
                            let filterData = data.data;
                            if (filterData.success) {
                                _this.params = filterData.data[0];
                            }
                            _this.loading = false;
                        }).catch((error) => {
                            console.error(error)
                        })
                    },
                    userEdit() {
                        let _this = this;
                        axios.post('/api/admin/msg/edit', _this.params)
                            .then((data) => {
                                let filterData = data.data;
                                if (filterData.success && filterData.data.affectedRows === 1) {
                                    tips(_this, '更新成功^_^');
                                    _this.$router.go(-1);
                                } else {
                                    _this.tips(filterData.msg)
                                }
                            })
                            .catch((error) => {
                                console.log(error);
                            });
                    }
                    ,
                    checkForm: function () {
                        var _this = this;
                        if (!hasPermission('10')) {
                            tipsWarn(_this, '对不起,您没有操作权限^_^');
                            return
                        }
                        var fm = document.form;

                        if (_this.params.title == '') {
                            tipsWarn(_this, '标题不能为空^_^');
                            fm.title.focus();
                            return false;
                        }


                        if (_this.params.content == '') {
                            tipsWarn(_this, '内容不能为空，且不能大于200位^_^');
                            fm.content.focus();
                            return false;
                        }

                        console.log(_this.params)
                        _this.userEdit();
                    }

                },

                created: function () {
                    this.queryById()
                },
                mounted: function () {
                }

            });
        </script>
</body>

</html>